home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / xdme_1.84_src.lha / XDME / Src / Menu / MenuStrips.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-02  |  48.1 KB  |  2,304 lines

  1. /******************************************************************************
  2.  
  3.     MODUL
  4.     menustrips.c
  5.  
  6.     DESCRIPTION
  7.     lowlevel commands to support programmable menues
  8.     which are designed to invoke commands of a destinct
  9.     macro language
  10.  
  11.     NOTES
  12.     exerimental phase
  13.  
  14.     Eine wichtige Aenderung sollte zur Einbindung dieser Functionen
  15.     in dem [X]DME vorgenommen werden:
  16.         in Zukunft hat immer nur maximal eins - das aktive Fenster -
  17.         eine MenueLeiste; fuer den Benutzer ist dies im
  18.         Allgemeinen nicht weiter von Bedeutung, da er
  19.         ohnehin nur das Menue des aktiven Fensters benutzen kann.
  20.         wenn er also waehrend eines laengeren Macros die fenster
  21.         wechselt, und in einem anderen Fenster eine Eingabe machen
  22.         will - die ohnehin erst nach Beendigung des Macros ausgefuehrt
  23.         wuerde, so wird ihm so gezeigt, dass er noch gar keine Eingabe
  24.         machen kann.
  25.  
  26.     Eine weitere Aenderung sollte stattfinden mit MACRO
  27.         kuenftig sollte ausschliesslich eine opaque typ Macro uebergeben
  28.         werden, die AUSSERHALB von menubase.c initialisiert wurde;
  29.         dies jedoch birgt enorme probleme bei fktionen wie menudel,
  30.         da diese nicht einfach die freiwerdenen macros zurueckgeben
  31.         koennen, sondern dann wiederum selbststaendig die macros loeschen
  32.         muessen
  33.         (es ist wahrscheinlich, dass die neue version der PL keine
  34.         Bindung zwischen funktionen und Help kennt, daher muessten dann
  35.         MACROS bestehen aus einer Node, die 2 Strings klammert:
  36.         den Funktionsaufruf und den Hilfstext)
  37.         (die entscheidung spielt aber auch in diesem Modul eine Rolle
  38.         da unter Umstaenden menuload/menusave an das neue Macrohandling
  39.         angepasst werden muessen; die betreffenden Stellen wurden
  40.         soweit sie erkannt wurden geklammert mit dem folgenden Kommentar:
  41.         --- THAT BLOCK MUST BE CHANGED IF MACROS ARE MODIFIED
  42.  
  43.  
  44.     BUGS
  45.     IMPORTANT
  46.         we cannot actually react on ERRORs !!
  47.  
  48.     TODO
  49.     [SUB] - MX-CheckItems
  50.     Help-Texts - dies ist ein thema, das m.E mehr fuer Macros.c gedacht ist - oder ?
  51.     fix_items
  52.     include some error()-calls
  53.  
  54.     wuenschenwert ist eine groessere abstraktion:
  55.         es wird vermutlich eine opaque type XITEM
  56.         mit den funktionen
  57.         create,   delete,  getcheck, setcheck, settype,  gettype,
  58.         setmacro, sethelp, addsub,   getname,  getmacro, gethelp
  59.         erzeugt werden. (in diesem augenblick muss eine wesentlich
  60.         striktere memory-kontrolle eingefuhrt werden)
  61.  
  62.         es ist ueberlegenswert, ob doppelbenennungen nicht doch erlaubt werden sollen ????
  63.         ( xi = new_xitem (name, type); add_xitem (menuheader, xi); )
  64.  
  65.     EXAMPLES
  66.  
  67.     SEE ALSO
  68.  
  69.     INDEX
  70.     $Header : $
  71.  
  72.     HISTORY
  73.     18 Dec 1992 b_null created
  74.     20-Jan 1993 b_null added checkitems
  75.     27 Jan 1993 b_null added multiple menustrips (renamed menubase -> menustrips)
  76.     $Date: 1994/09/20 11:09:14 $ last update
  77.  
  78. ******************************************************************************/
  79.  
  80. /**************************************
  81.         Includes
  82. **************************************/
  83. #define  MENU_INTERNAL
  84. #include "defs.h"
  85. #include "menubase.h"
  86.  
  87.  
  88. /**************************************
  89.         Globale Variable
  90. **************************************/
  91.  
  92. Prototype void        menuclear   (MENUSTRIP *ms);
  93. Prototype int        menudel     (MENUSTRIP *ms, char *tname);
  94. static      struct Menu * getmenu     (MENUSTRIP *ms, char *tname);
  95. static      XITEM *    getitem     (MENUSTRIP *ms, char *tname, char *iname);
  96. static      XITEM *    getsub        (MENUSTRIP *ms, char *tname, char *iname, char *sname);
  97. Prototype int        itemdel     (MENUSTRIP *ms, char *tname, char *iname);
  98. Prototype int        subdel        (MENUSTRIP *ms, char *tname, char *iname, char *sname);
  99. Prototype XITEM *    itemadd     (MENUSTRIP *ms, char *tname, char *iname,              char *macro, char *help, int check, char *scut);
  100. Prototype XITEM *    subadd        (MENUSTRIP *ms, char *tname, char *iname, char *sname, char *macro, char *help, int check, char *scut);
  101. Prototype int        loadmenus   (MENUSTRIP *ms, FILE *fi,     int *lineno);
  102. Prototype int        savemenus   (MENUSTRIP *ms, FILE *fo);
  103. Prototype int        chkitemcheck(MENUSTRIP *ms, char *tname, char *iname);
  104. Prototype int        chksubcheck (MENUSTRIP *ms, char *tname, char *iname, char *sname);
  105. Prototype int        setitemcheck(MENUSTRIP *ms, char *tname, char *iname,              int status);
  106. Prototype int        setsubcheck (MENUSTRIP *ms, char *tname, char *iname, char *sname, int status);
  107. Prototype APTR        menu2macro  (MENUSTRIP *ms, char *str);
  108.  
  109. Prototype MENUSTRIP *get_menustrip    (char * name);
  110. Prototype MENUSTRIP *new_menustrip    (char * name, int defaults);
  111. Prototype void         delete_menustrip (MENUSTRIP * kt, int force);
  112.  
  113. Prototype void         exit_menustrips (void);
  114.  
  115. /**************************************
  116.       Interne Defines & Strukturen
  117. **************************************/
  118. #define MENU_DELIMITER '-'  /* the char that divides menuename from itemname */
  119. #define ITEM_DELIMITER '-'  /* the char that divides itemname from subitemname */
  120.  
  121. #define SCUT(xi)  ((xi)->item.Flags & COMMSEQ)
  122. #define SCUTS(xi) ((SCUTS_dummy[0]=(xi)->item.Command)? SCUTS_dummy: SCUTS_dummy)
  123.  
  124.  
  125. /**************************************
  126.         Interne Variable
  127. **************************************/
  128.  
  129. #define cmpfunc(x,y) stricmp(x,y) /* if s.o wishes case-sensitivity redefine here */
  130.  
  131. static struct Image SepImage = {
  132.     1,    /* left */
  133.     1,    /* top    */
  134.     0,    /* wid. */
  135.     2,    /* hig. */
  136.     0,    /* dep. */
  137.     NULL,/* data */
  138.     0,    /* ppik */
  139.     0,    /* poo    */
  140.     NULL/* next */
  141. };
  142.  
  143. static struct MinList _MenuStrips;
  144. APTR MenuRoot    = NULL;
  145. APTR MenuStrips = NULL;
  146.  
  147. static char SCUTS_dummy[2] = { 0, 0 };
  148.  
  149. /**************************************
  150.        Interne Prototypes
  151. **************************************/
  152. static    XITEM * DeleteXItem      (XITEM  *xi);
  153. static    XITEM * CreateXItem      (char   *name);
  154. static    XITEM * get_xitem      (XITEM  *start, char *name);
  155. static    XITEM * mod_or_add_xitem  (XITEM **pr,    char *name, char *macro, char *help, int check, char *scut);
  156. static    int    rem_xitem      (XITEM **pr,    char *name);
  157.  
  158.  
  159. /* !!! achtung irgendwo muessen noch menuoff/menuon eingebaut werden !!! */
  160.  
  161.  
  162.  
  163.  
  164. /*****************************************************************************
  165.  
  166.     NAME
  167.     DeleteXItem
  168.  
  169.     PARAMETER
  170.     XITEM * xi
  171.  
  172.     RESULT
  173.     xi->next
  174.  
  175.     RETURN
  176.     XITEM *
  177.  
  178.     DESCRIPTION
  179.     remove an xitem and all associated data (name, help, com, subs)
  180.  
  181.     NOTES
  182.  
  183.     BUGS
  184.  
  185.     EXAMPLES
  186.  
  187.     SEE ALSO
  188.  
  189.     INTERNALS
  190.     text ? loesche text
  191.     loesche xitem
  192.  
  193.     HISTORY
  194.     18 Dec 1992 b_noll  created
  195.     03 Feb 1993 b_noll rewritten
  196.     29 Oct 1994 b_noll added idenfifier support
  197.  
  198. ******************************************************************************/
  199.  
  200. static
  201. XITEM * DeleteXItem (XITEM * xi)
  202. {
  203.     if (xi) {
  204.     XITEM * next = (XITEM *)xi->item.NextItem;
  205.  
  206.     if (xi->item.Flags & ITEMTEXT) {
  207.         struct IntuiText * it = &xi->fill.it;
  208.         XITEM * sub = (XITEM *)xi->item.SubItem;
  209.  
  210.         while (sub)    { sub = DeleteXItem (sub); } /* while */
  211.         if (it->IText) { DeallocFunc (it->IText); } /* if */
  212.         if (xi->help)  { DeallocFunc (xi->help);  } /* if */
  213.         if (xi->com)   { DeallocFunc (xi->com);   } /* if */
  214.         if (it->IText != xi->identifier) { DeallocFunc(xi->identifier); } /* if */
  215.     } /* if is text */
  216.  
  217.     FreeFunc (xi, sizeof (XITEM));
  218.     return (next);
  219.     } /* if */
  220.  
  221.     return (NULL);
  222. } /* DeleteXItem */
  223.  
  224.  
  225.  
  226. /*****************************************************************************
  227.  
  228.     NAME
  229.     get_xitem
  230.  
  231.     PARAMETER
  232.     XITEM * start
  233.     char  * name
  234.  
  235.     RESULT
  236.     a item connected with name that is on the same level
  237.     and later than start or start itself
  238.     NULL if not found
  239.  
  240.     RETURN
  241.     XITEM *
  242.  
  243.     DESCRIPTION
  244.     this function can be used to search for entries in a certain level
  245.  
  246.     NOTES
  247.  
  248.     BUGS
  249.  
  250.     EXAMPLES
  251.  
  252.     SEE ALSO
  253.  
  254.     INTERNALS
  255.  
  256.     HISTORY
  257.     19 Dec 1992 b_noll  created
  258.     29 Oct 1994 b_noll added idenfifier support
  259.  
  260. ******************************************************************************/
  261.  
  262. static
  263. XITEM * get_xitem (XITEM * start, char * name)
  264. {
  265.     struct MenuItem * item;
  266.  
  267.     for (item = (struct MenuItem *)start; item; item = item->NextItem) {
  268.     if ((item->Flags & ITEMTEXT) == 0) {
  269.         if (name == BAR) {
  270.         return ((XITEM *)item);
  271.         } /* if */
  272.     } else if (name != BAR) {
  273.         if (strcmp (((XITEM *)item)->identifier, name) == 0) {
  274.         return ((XITEM *)item);
  275.         } /* if */
  276.     } /* if */
  277.     } /* for */
  278.  
  279.     return (NULL);
  280. } /* get_xitem */
  281.  
  282.  
  283.  
  284. /*****************************************************************************
  285.  
  286.     NAME
  287.     getmenu
  288.  
  289.     PARAMETER
  290.     MENUSTRIP * ms
  291.     char      * tname
  292.  
  293.     RESULT
  294.     the menuentry connected to tname
  295.     NULL if not found
  296.  
  297.     RETURN
  298.     struct Menu *
  299.  
  300.     DESCRIPTION
  301.  
  302.     NOTES
  303.  
  304.     BUGS
  305.  
  306.     EXAMPLES
  307.  
  308.     SEE ALSO
  309.  
  310.     INTERNALS
  311.  
  312.     HISTORY
  313.     19 Dec 1992 b_noll  created
  314.  
  315. ******************************************************************************/
  316.  
  317. static
  318. struct Menu * getmenu (MENUSTRIP * ms, char * tname)
  319. {
  320.     struct Menu * menu;
  321.  
  322.     if (ms == NULL) {
  323.     return (NULL);
  324.     } /* if */
  325.  
  326.     for (menu = ms->data; menu; menu = menu->NextMenu) {
  327.     if (strcmp (menu->MenuName, tname) == 0) {
  328.         return (menu);
  329.     } /* if */
  330.     } /* for */
  331.     return (NULL);
  332. } /* getmenu */
  333.  
  334.  
  335.  
  336. /*****************************************************************************
  337.  
  338.     NAME
  339.     getitem
  340.  
  341.     PARAMETER
  342.     MENUSTRIP * ms
  343.     char      * tname
  344.     char      * iname
  345.  
  346.     RESULT
  347.     the itementry connected to tname/iname
  348.     NULL if not found
  349.  
  350.     RETURN
  351.     XITEM *
  352.  
  353.     DESCRIPTION
  354.  
  355.     NOTES
  356.  
  357.     BUGS
  358.  
  359.     EXAMPLES
  360.  
  361.     SEE ALSO
  362.  
  363.     INTERNALS
  364.  
  365.     HISTORY
  366.     19 Dec 1992 b_noll  created
  367.  
  368. ******************************************************************************/
  369.  
  370. static
  371. XITEM * getitem (MENUSTRIP * ms, char * tname, char * iname)
  372. {
  373.     struct Menu * menu = getmenu (ms, tname);
  374.  
  375.     if (menu) {
  376.     return (get_xitem ((XITEM *)menu->FirstItem, iname));
  377.     } /* if */
  378.     return (NULL);
  379. } /* getitem */
  380.  
  381.  
  382.  
  383. /*****************************************************************************
  384.  
  385.     NAME
  386.     getsub
  387.  
  388.     PARAMETER
  389.     MENUSTRIP * ms
  390.     char      * tname
  391.     char      * iname
  392.     char      * sname
  393.  
  394.     RESULT
  395.     the subentry connected to tname/iname/sname
  396.     NULL if not found
  397.  
  398.     RETURN
  399.     XITEM *
  400.  
  401.     DESCRIPTION
  402.  
  403.     NOTES
  404.  
  405.     BUGS
  406.  
  407.     EXAMPLES
  408.  
  409.     SEE ALSO
  410.  
  411.     INTERNALS
  412.  
  413.     HISTORY
  414.     19 Dec 1992 b_noll  created
  415.  
  416. ******************************************************************************/
  417.  
  418. static
  419. XITEM * getsub (MENUSTRIP * ms, char * tname, char * iname, char * sname)
  420. {
  421.     struct MenuItem * parent = (struct MenuItem *)getitem (ms, tname, iname);
  422.  
  423.     if (parent) {
  424.     return (get_xitem ((XITEM *)parent->SubItem, sname));
  425.     } /* if */
  426.  
  427.     return (NULL);
  428. } /* getsub */
  429.  
  430.  
  431.  
  432. /*****************************************************************************
  433.  
  434.     NAME
  435.     menudel
  436.  
  437.     PARAMETER
  438.     MENUSTRIP * ms
  439.     char      * tname
  440.  
  441.     RESULT
  442.     success:
  443.         RET_FAIL - Menu was not found
  444.         RET_SUCC - Menu deleted
  445.  
  446.     RETURN
  447.     int
  448.  
  449.     DESCRIPTION
  450.  
  451.     NOTES
  452.  
  453.     BUGS
  454.  
  455.     EXAMPLES
  456.  
  457.     SEE ALSO
  458.     menucom/do_delmenu
  459.  
  460.     INTERNALS
  461.  
  462.     HISTORY
  463.     19 Dec 1992 b_noll created
  464.     20 Jan 1993 b_noll changed return to int
  465.  
  466. ******************************************************************************/
  467.  
  468. int menudel (MENUSTRIP * ms, char * tname)
  469. {
  470.     struct Menu *  menu;
  471.     struct Menu ** pr;
  472.     XITEM    *  xi;
  473.  
  474.     if (ms == NULL) {
  475.     return (RET_FAIL);
  476.     } /* if */
  477.     pr = &ms->data;
  478.  
  479.     for (menu = *pr; menu; pr = &menu->NextMenu, menu = *pr) {
  480.     if (strcmp (tname, menu->MenuName) == 0) {
  481.         break;
  482.     } /* if menu exists */
  483.     } /* for all headers */
  484.  
  485.     if (menu) {
  486.     /* --- detach from list */
  487.     *pr = menu->NextMenu;
  488.  
  489.     /* --- delete all items */
  490.     xi = (XITEM *)menu->FirstItem;
  491.     while (xi) {
  492.         xi = DeleteXItem (xi);
  493.     } /* while */
  494.  
  495.     /* --- free data */
  496.     DeallocFunc (menu->MenuName);
  497.     FreeFunc    (menu, sizeof (struct Menu));
  498.  
  499.     return (RET_SUCC);
  500.     } /* if */
  501.  
  502.     return (RET_FAIL);
  503. } /* menudel */
  504.  
  505.  
  506.  
  507. /*****************************************************************************
  508.  
  509.     NAME
  510.     rem_xitem
  511.  
  512.     PARAMETER
  513.     XITEM ** pr
  514.     char   * name
  515.  
  516.     RESULT
  517.     success:
  518.         RET_FAIL - item name not found or wrong syntax
  519.         RET_SUCC - ok
  520.  
  521.     RETURN
  522.     int
  523.  
  524.     DESCRIPTION
  525.  
  526.     NOTES
  527.  
  528.     BUGS
  529.  
  530.     EXAMPLES
  531.  
  532.     SEE ALSO
  533.  
  534.     INTERNALS
  535.  
  536.     HISTORY
  537.     19 Dec 1992 b_noll  created
  538.  
  539. ******************************************************************************/
  540.  
  541. static
  542. int rem_xitem (XITEM ** pr, char * name)
  543. {
  544.     XITEM * xi;
  545.  
  546.     if (pr == NULL || name == NULL) {
  547.     return (RET_FAIL);
  548.     } else if (name == BAR) {
  549.     for (xi = *pr; xi; pr = (XITEM **)&xi->item.NextItem, xi = *pr) {
  550.         if (!(xi->item.Flags & ITEMTEXT)) {
  551.         break;
  552.         } /* if found */
  553.     } /* for all entries */
  554.     } else {
  555.     for (xi = *pr; xi; pr = (XITEM **)&xi->item.NextItem, xi = *pr) {
  556.         if (xi->item.Flags & ITEMTEXT) {
  557.         char * inter = (char *)((struct IntuiText *) xi->item.ItemFill)->IText;
  558.         if (strcmp (inter, name) == 0) {
  559.             break;
  560.         } /* if found */
  561.         } /* if no BAR */
  562.     } /* for all items  */
  563.     } /* if (no) bar/name */
  564.  
  565.     if (xi) {
  566.     *pr = (XITEM *)DeleteXItem (xi);
  567.     return (RET_SUCC);
  568.     } /* if */
  569.  
  570.     return (RET_FAIL);
  571. } /* rem_xitem */
  572.  
  573.  
  574.  
  575. /*****************************************************************************
  576.  
  577.     NAME
  578.     itemdel
  579.  
  580.     PARAMETER
  581.     MENUSTRIP * ms
  582.     char      * tname
  583.     char      * iname
  584.  
  585.     RESULT
  586.     success:
  587.         RET_FAIL - item name not found or wrong syntax
  588.         RET_SUCC - ok
  589.  
  590.     RETURN
  591.     int
  592.  
  593.     DESCRIPTION
  594.  
  595.     NOTES
  596.  
  597.     BUGS
  598.  
  599.     EXAMPLES
  600.  
  601.     SEE ALSO
  602.     menucom/do_delitem, menucom/do_delitembar
  603.  
  604.     INTERNALS
  605.  
  606.     HISTORY
  607.     19 Dec 1992 b_noll created
  608.  
  609. ******************************************************************************/
  610.  
  611. int itemdel (MENUSTRIP * ms, char * tname, char * iname)
  612. {
  613.     int succ = RET_FAIL;
  614.     struct Menu * menu = getmenu (ms, tname);
  615.  
  616.     if (menu) {
  617.     succ = rem_xitem ((XITEM **)&menu->FirstItem, iname);
  618.  
  619.     if (succ && !menu->FirstItem) {
  620.         menudel (ms, tname);
  621.     } /* if */
  622.     } /* if */
  623.     return (succ);
  624. } /* itemdel */
  625.  
  626.  
  627.  
  628. /*****************************************************************************
  629.  
  630.     NAME
  631.     subdel
  632.  
  633.     PARAMETER
  634.     MENUSTRIP * ms
  635.     char      * tname
  636.     char      * iname
  637.     char      * sname
  638.  
  639.     RESULT
  640.     success:
  641.         RET_FAIL - item name not found or wrong syntax
  642.         RET_SUCC - ok
  643.  
  644.     RETURN
  645.     int
  646.  
  647.     DESCRIPTION
  648.  
  649.     NOTES
  650.  
  651.     BUGS
  652.  
  653.     EXAMPLES
  654.  
  655.     SEE ALSO
  656.     menucom/do_delsub, menucom/do_delsubbar
  657.  
  658.     INTERNALS
  659.  
  660.     HISTORY
  661.     19 Dec 1992 b_noll created
  662.  
  663. ******************************************************************************/
  664.  
  665. int subdel (MENUSTRIP * ms, char * tname, char * iname, char * sname)
  666. {
  667.     int succ = RET_FAIL;
  668.     struct MenuItem * item = (struct MenuItem *)getitem (ms, tname, iname);
  669.  
  670.     if (item) {
  671.     succ = rem_xitem ((XITEM **)&item->SubItem, sname);
  672.     if (succ && !item->SubItem) {
  673.         itemdel (ms, tname, iname);
  674.     } /* if */
  675.     } /* if */
  676.     return (succ);
  677. } /* subdel */
  678.  
  679.  
  680.  
  681. /*****************************************************************************
  682.  
  683.     NAME
  684.     menuadd
  685.  
  686.     PARAMETER
  687.     MENUSTRIP * ms
  688.     char      * tname
  689.  
  690.     RESULT
  691.     success :
  692.         ==NULL = failure
  693.         !=NULL = ok (address of menu)
  694.  
  695.     RETURN
  696.     struct Menu *
  697.  
  698.     DESCRIPTION
  699.     we try to add a new menu-header to a menubar
  700.     if it does not already exist; else we simply return it
  701.  
  702.     NOTES
  703.  
  704.     BUGS
  705.  
  706.     EXAMPLES
  707.  
  708.     SEE ALSO
  709.  
  710.     INTERNALS
  711.     falls das menu schon existiert,
  712.         gib es einfach zurueck
  713.  
  714.     erzeuge einen neuen body und
  715.     ein namens-string,
  716.     fuelle es
  717.     und gib es zurueck
  718.  
  719.     HISTORY
  720.     18 Dec 1992 b_null  created
  721.  
  722. ******************************************************************************/
  723.  
  724. static
  725. struct Menu * menuadd (MENUSTRIP * ms, char * tname)
  726. {
  727.     struct Menu *  menu;
  728.     struct Menu ** pr;
  729.  
  730.     if (ms == NULL || tname == NULL) {
  731.     return (NULL);
  732.     } /* if */
  733.  
  734.     pr = &ms->data;
  735.  
  736.     for (menu = *pr; menu; pr = &menu->NextMenu, menu = *pr) {
  737.     if (strcmp (tname, menu->MenuName) == 0) {
  738.         return (menu);
  739.     } /* if menu exists */
  740.     } /* for all headers */
  741.  
  742.     menu = AllocFunc (sizeof(struct Menu), MEMF_ANY);
  743.     if (!menu) {
  744.     return (NULL);
  745.     } /* if no heap for menu */
  746.     setmem (menu, sizeof(struct Menu), 0);
  747.  
  748.     menu->MenuName = DupFunc (tname, MEMF_ANY);
  749.     if (!menu->MenuName) {
  750.     FreeFunc (menu, sizeof (struct Menu));
  751.     return (NULL);
  752.     } /* if no heap for name */
  753.  
  754.     menu->NextMenu = *pr; /* == NULL */
  755.     *pr = menu;
  756.     menu->Flags = MENUENABLED;
  757.  
  758.     return (menu);
  759. } /* menuadd */
  760.  
  761.  
  762.  
  763. /*****************************************************************************
  764.  
  765.     NAME
  766.     CreateXItem
  767.  
  768.     PARAMETER
  769.     char * name
  770.  
  771.     RESULT
  772.     new XITEM
  773.  
  774.     RETURN
  775.     XITEM *
  776.  
  777.     DESCRIPTION
  778.     creates a new XITEM and all additional data
  779.     does NOT link a macro
  780.  
  781.     NOTES
  782.  
  783.     BUGS
  784.  
  785.     EXAMPLES
  786.  
  787.     SEE ALSO
  788.  
  789.     INTERNALS
  790.     get heap fuer body
  791.     fehler ? -> abbruch
  792.     alles loeschen
  793.     BAR ?
  794.     ja-> data initialisieren
  795.     nein-> get heap fuer string
  796.         fehler ? -> abbruch
  797.         data initailisieren
  798.     ptr auf body zurueck
  799.  
  800.     HISTORY
  801.     18 Dec 1992 b_noll created
  802.     29 Oct 1994 b_noll added idenfifier support
  803.  
  804. ******************************************************************************/
  805.  
  806. static
  807. XITEM * CreateXItem (char * name)
  808. {
  809.     XITEM        * xi;
  810.     struct MenuItem * item;
  811.  
  812.     xi = AllocFunc (sizeof (XITEM), MEMF_ANY);
  813.     if (!xi) {
  814.     return (NULL);
  815.     } /* if no heap for body */
  816.  
  817.     setmem (xi, sizeof(XITEM), 0);
  818.     item       = &xi->item;
  819.     item->ItemFill = &xi->fill;
  820.     item->SubItem  = NULL;    /* doppelt gemoppelt haelt besser */
  821.  
  822.     if (name == BAR) {
  823.     struct Image * im = &xi->fill.im;
  824.     //xi->identifier = "(BAR)";
  825.  
  826.     memcpy (im, &SepImage, sizeof (struct Image));
  827.     item->Flags = HIGHNONE; /* HIGHCOMP; */
  828.     } else {
  829.     struct IntuiText * it = &xi->fill.it;
  830.  
  831.     xi->identifier = it->IText = DupFunc (name, MEMF_ANY);
  832.     if (!it->IText) {
  833.         FreeFunc (xi, sizeof(XITEM));
  834.         return (NULL);
  835.     } /* if */
  836.  
  837. #if 0
  838.     it->BackPen    = 1;    /* These values are set in fixmenu - i hope */
  839.     it->FrontPen   = 0;    /* These values are set in fixmenu - i hope */
  840.     it->DrawMode   = JAM2; /* These values are set in fixmenu - i hope */
  841. #endif
  842.  
  843.     item->Flags    = ITEMTEXT|ITEMENABLED|HIGHCOMP;
  844.     } /* if */
  845.  
  846.     return (xi);
  847. } /* CreateXItem */
  848.  
  849.  
  850.  
  851. /*****************************************************************************
  852.  
  853.     NAME
  854.     mod_or_add_xitem
  855.  
  856.     PARAMETER
  857.     XITEM **root
  858.     char   *name
  859.     char   *macro
  860.     char   *help
  861.     int    check
  862.        char    *scut
  863.  
  864.     RESULT
  865.     found&modifed or created XITEM or NULL
  866.  
  867.     RETURN
  868.     XITEM *
  869.  
  870.     DESCRIPTION
  871.     try to find name in the list after pr
  872.     if not found, try to create a new one
  873.     return the result or the found
  874.     (bars are always added)
  875.  
  876.     NOTES
  877.  
  878.     BUGS
  879.     scut is not yet used
  880.  
  881.     EXAMPLES
  882.  
  883.     SEE ALSO
  884.  
  885.     INTERNALS
  886.     ein BAR immer neu
  887.     sonst suche nach name
  888.         eintrag gefunden -> modifiziere ihn & gib ihn zurueck
  889.     erzeuge neuen eintrag
  890.     und gib ihn zurueck
  891.  
  892.     HISTORY
  893.     18 Dec 1992 b_noll  created
  894.     22 Jun 1994 b_noll added scut
  895.     29 Oct 1994 b_noll added idenfifier support
  896.  
  897. ******************************************************************************/
  898.  
  899. static
  900. XITEM * mod_or_add_xitem (XITEM **root, char *name, char *macro, char *help, int check, char *scut)
  901. {
  902.     XITEM *  xi;
  903.     XITEM ** pr = root;
  904.  
  905.     if (root == NULL || name == NULL) {
  906.     return (NULL);
  907.     } else if (name == BAR) {
  908.     for (xi = *pr; xi; pr = (XITEM **)&xi->item.NextItem, xi = *pr) {
  909.         /* do nothing - just go to the end of the list */
  910.     } /* for all entries */
  911.     } else {
  912.     for (xi = *pr; xi; pr = (XITEM **)&xi->item.NextItem, xi = *pr) {
  913.         if (xi->item.Flags & ITEMTEXT) {
  914.         if (strcmp (xi->identifier, name) == 0) {
  915.             break;
  916.         } /* if found */
  917.         } /* if no BAR */
  918.     } /* for all items */
  919.     } /* if (no) bar/name */
  920.  
  921.     /* --- not found create a new one */
  922.     if (!xi) {
  923.     xi = CreateXItem (name);
  924.     if (xi == NULL) {
  925.         return (NULL);
  926.     } /* if fail */
  927.     } /* if */
  928.  
  929.     *pr = (XITEM *)xi->item.NextItem; /* zunaechst aus der liste loesen */
  930.  
  931.     /*
  932.     ** das sollte bei gelegenheit geaendert werden:
  933.     ** so ist es nicht moegich, ein macro zu loeschen...
  934.     */
  935.  
  936.     if (name != BAR) {
  937.     /* dies bedeutet unnoetige fragmentation : wir sollten besser erst nachschauen, ob sich werte veraendert haben */
  938.     DeallocFunc (xi->com);  xi->com  = NULL;
  939.     DeallocFunc (xi->help); xi->help = NULL;
  940.  
  941.     if (macro) {
  942.         {    /* A MACRO-CARRIER MUST NOT BE A SUB-CARRIER */
  943.         XITEM * sub = (XITEM *)xi->item.SubItem;
  944.         while (sub) {
  945.             sub = DeleteXItem (sub);
  946.         } /* while */
  947.         }
  948.  
  949.         if (check) {
  950.         xi->item.Flags |= CHECKIT|MENUTOGGLE;
  951.         } else {
  952.         xi->item.Flags &= ~(CHECKIT|MENUTOGGLE);
  953.         } /* if */
  954.  
  955.         if (!(xi->com = DupFunc (macro, MEMF_ANY))) {
  956.         DeleteXItem (xi);
  957.         return (NULL);
  958.         } /* if !replaced */
  959.  
  960.         if (scut) {
  961.         xi->item.Flags    |=  COMMSEQ;
  962.         xi->item.Command = *scut;
  963.         } /* if */
  964.     } /* if (macro) */
  965.  
  966.     if (help) {
  967.         if (!(xi->help = DupFunc (help, MEMF_ANY))) {
  968.         DeleteXItem (xi);
  969.         return (NULL);
  970.         } /* if !replaced */
  971.     } /* if (help) */
  972.  
  973.  
  974.     } /* if (!bar) */
  975.  
  976.     *pr = xi; /* (wieder) einhaengen erst wenn alles ok */
  977.     return (xi);
  978. } /* mod_or_add_xitem */
  979.  
  980.  
  981.  
  982. /*****************************************************************************
  983.  
  984.     NAME
  985.     itemadd
  986.  
  987.     PARAMETER
  988.     MENUSTRIP * ms
  989.     char      * tname
  990.     char      * iname
  991.     char      * macro
  992.     char      * help
  993.     int        check
  994.  
  995.     RESULT
  996.     success :
  997.         ==NULL = failure
  998.         !=NULL = ok      (address of item)
  999.  
  1000.     RETURN
  1001.     XITEM *
  1002.  
  1003.     DESCRIPTION
  1004.     find a menuitem-structure of the right names
  1005.     and create one at the end of the list,
  1006.     if there is none.
  1007.     (we try to add a item-structure to menubar)
  1008.  
  1009.     NOTES
  1010.  
  1011.     BUGS
  1012.  
  1013.     EXAMPLES
  1014.  
  1015.     SEE ALSO
  1016.     menucom/do_itemadd, menucom/do_itembar
  1017.  
  1018.     INTERNALS
  1019.     finde das richtige menu
  1020.     falls der eintrag nicht existiert
  1021.         erzeuge einen neuen
  1022.     revidiere das commando
  1023.     gib den eintrag zurueck
  1024.  
  1025.     HISTORY
  1026.     18 Dec 1992 b_null  created
  1027.     22 Jun 1994 b_null added scut
  1028.  
  1029. ******************************************************************************/
  1030.  
  1031. XITEM * itemadd (MENUSTRIP *ms, char *tname, char *iname, char *macro, char *help, int check, char *scut)
  1032. {
  1033.     struct Menu  * menu;
  1034.     XITEM     * item;
  1035.  
  1036. /* /*  */
  1037.  /* return NULL; */
  1038.  
  1039.     if (!(menu = menuadd (ms, tname))) {
  1040.     return (NULL);
  1041.     } /* if no header */
  1042.  
  1043.     /* menues have no commands -> no comcheck */
  1044.  
  1045.     item = mod_or_add_xitem ((XITEM **)&menu->FirstItem, iname, macro, help, check, scut);
  1046.     if (item == NULL && menu->FirstItem == NULL) {
  1047.     menudel (ms, tname);
  1048.     return (NULL);
  1049.     } /* if fail and only item */
  1050.  
  1051.     return (item);
  1052. } /* itemadd */
  1053.  
  1054.  
  1055.  
  1056. /*****************************************************************************
  1057.  
  1058.     NAME
  1059.     subadd
  1060.  
  1061.     PARAMETER
  1062.     MENUSTRIP * ms
  1063.     char      * tname
  1064.     char      * iname
  1065.     char      * sname
  1066.     char      * macro
  1067.     char      * help
  1068.     int        check
  1069.     char       *scut
  1070.  
  1071.     RESULT
  1072.     success : ==NULL = failure !=NULL = ok
  1073.  
  1074.     RETURN
  1075.     XITEM *
  1076.  
  1077.     DESCRIPTION
  1078.     we try to add a subitem-structure to to menubar
  1079.  
  1080.     NOTES
  1081.  
  1082.     BUGS
  1083.  
  1084.     EXAMPLES
  1085.     menucom/do_subadd, menucom/do_subbar
  1086.  
  1087.     SEE ALSO
  1088.  
  1089.     INTERNALS
  1090.     falls es kein item mit menu/item mit d. richtigen namen gibt,
  1091.         erzeuge eins
  1092.         falls das fehlschug -> abbruch
  1093.  
  1094.     falls das item ein eigenes macro hat und daher keine
  1095.         subs unterstuetzt -> abbruch
  1096.  
  1097.     falls es noch kein sub mit dem richtigen namen gibt,
  1098.         erzeuge eins (bars werden immer addiert)
  1099.  
  1100.     falls das fehlschlug und extra ein item rzeugt worden war,
  1101.         loesche das wieder -> abbruch
  1102.  
  1103.  
  1104.     HISTORY
  1105.     18 Dec 1992 b_null created
  1106.     22 Jun 1994 b_null added scut
  1107.  
  1108. ******************************************************************************/
  1109.  
  1110. XITEM * subadd (MENUSTRIP *ms, char *tname, char *iname, char *sname, char *macro, char *help, int check, char *scut)
  1111. {
  1112.     XITEM        * item;
  1113.     XITEM        * sub;
  1114.  
  1115.     if (iname == BAR) {
  1116.     return (NULL);
  1117.     } /* if item=bar -    ein bar soll untermenues haben ??? */
  1118.  
  1119.     if (!(item = itemadd (ms, tname, iname, NULL, NULL, 0, NULL))) {
  1120.     return (NULL);
  1121.     } /* if no item */
  1122.  
  1123.     if (item->com != NULL) {
  1124.     return (NULL);
  1125.     } /* if no subs allowed */
  1126.  
  1127.     sub = mod_or_add_xitem ((XITEM **)&item->item.SubItem, sname, macro, help, check, scut);
  1128.     if (sub == NULL && item->item.SubItem == NULL) {
  1129.     itemdel (ms, tname, iname);
  1130.     return (NULL);
  1131.     } /* if fail and only sub */
  1132.  
  1133.     return (sub);
  1134. } /* subadd */
  1135.  
  1136.  
  1137.  
  1138. /*****************************************************************************
  1139.  
  1140.     NAME
  1141.     savemenus
  1142.  
  1143.     PARAMETER
  1144.     MENUSTRIP * ms
  1145.     FILE      * fo
  1146.  
  1147.     RESULT
  1148.     success (senseless for the moment)
  1149.  
  1150.     RETURN
  1151.     int
  1152.  
  1153.     DESCRIPTION
  1154.  
  1155.     NOTES
  1156.     we have used an implementation-decision here, that should
  1157.     better bew invisible -
  1158.     macros must be accessible via their name, if that model is used
  1159.     else we have to rewrite parts of that function
  1160.  
  1161.     BUGS
  1162.  
  1163.     EXAMPLES
  1164.  
  1165.     SEE ALSO
  1166.     menucom/do_menusave
  1167.  
  1168.     INTERNALS
  1169.  
  1170.     HISTORY
  1171.     19 Dec 1992 b_noll  rewritten for subs/subbars
  1172.  
  1173. ******************************************************************************/
  1174.  
  1175.  
  1176. int savemenus (MENUSTRIP * ms, FILE * fo)
  1177. {
  1178.     struct Menu     * menu;
  1179.     struct MenuItem * item;
  1180.  
  1181.     fprintf(fo, "MENUSTRIP START\n");
  1182.     for (menu= ms->data; menu; menu = menu->NextMenu) {
  1183.     fprintf(fo, "TITLE %s\n", menu->MenuName);
  1184.     for (item = menu->FirstItem; item; item = item->NextItem) {
  1185.         if (item->Flags & ITEMTEXT) {
  1186.         char* ptr = (char *)((struct IntuiText *)item->ItemFill)->IText;
  1187.         if (item->Flags & CHECKIT) {
  1188.             fprintf(fo, "\tITEMCHECK %s\n", ptr);
  1189. /* --- THAT BLOCK MUST BE CHANGED IF MACROS ARE MODIFIED */
  1190.             if (((XITEM *)item)->help)
  1191.                 fprintf (fo, "\t HELP %s\n", ((XITEM*)item)->help);
  1192.             if (SCUT((XITEM *)item))
  1193.                 fprintf (fo, "\t SHORT %s\n", SCUTS((XITEM *)item));
  1194.             fprintf(fo, "\t COM  %s\n", ((XITEM*)item)->com);
  1195. /* --- THAT BLOCK MUST BE CHANGED IF MACROS ARE MODIFIED */
  1196.         } else {
  1197.             fprintf(fo, "\tITEM %s\n", ptr);
  1198.             if (item->SubItem) {
  1199.             struct MenuItem * sub;
  1200.             for (sub = item->SubItem; sub; sub = sub->NextItem) {
  1201.                 if (sub->Flags & ITEMTEXT) {
  1202.                 char* ptr = (char *)((struct IntuiText *)sub->ItemFill)->IText;
  1203.                 if (sub->Flags & CHECKIT) {
  1204.                     fprintf (fo, "\t\tSUBCHECK %s\n", ptr);
  1205.                 } else {
  1206.                     fprintf (fo, "\t\tSUB %s\n", ptr);
  1207.                 } /* if */
  1208. /* --- THAT BLOCK MUST BE CHANGED IF MACROS ARE MODIFIED */
  1209.                 if (((XITEM *)item)->help)
  1210.                     fprintf (fo, "\t\t HELP %s\n", ((XITEM *)item)->help);
  1211.                 if (SCUT((XITEM *)item))
  1212.                     fprintf (fo, "\t\t SHORT %s\n", SCUTS((XITEM *)item));
  1213.                 fprintf (fo, "\t\t COM  %s\n", ((XITEM *)item)->com);
  1214. /* --- THAT BLOCK MUST BE CHANGED IF MACROS ARE MODIFIED */
  1215.                 } else {
  1216.                 fprintf (fo, "\t\tSUBBAR");
  1217.                 } /* if (not) text */
  1218.             } /* for subs */
  1219.             } else {
  1220. /* --- THAT BLOCK MUST BE CHANGED IF MACROS ARE MODIFIED */
  1221.             if (((XITEM *)item)->help)
  1222.                 fprintf (fo, "\t HELP %s\n", ((XITEM*)item)->help);
  1223.             if (SCUT((XITEM *)item))
  1224.                 fprintf (fo, "\t SHORT %s\n", SCUTS((XITEM *)item));
  1225.             fprintf(fo, "\t COM  %s\n", ((XITEM*)item)->com);
  1226. /* --- THAT BLOCK MUST BE CHANGED IF MACROS ARE MODIFIED */
  1227.             } /* if (not) subs */
  1228.         } /* if (not) checkitem */
  1229.         } else {
  1230.         fprintf(fo, "\tITEMBAR\n");
  1231.         } /* if (not) text */
  1232.     } /* for items */
  1233.     } /* for headers */
  1234.     fprintf(fo, "MENUSTRIP END\n");
  1235.  
  1236.     return (RET_SUCC);
  1237. } /* savemenus */
  1238.  
  1239.  
  1240.  
  1241. /*****************************************************************************
  1242.  
  1243.     NAME
  1244.     menuclear
  1245.  
  1246.     PARAMETER
  1247.     MENUSTRIP * ms
  1248.  
  1249.     RESULT
  1250.     -/-
  1251.  
  1252.     RETURN
  1253.     void
  1254.  
  1255.     DESCRIPTION
  1256.     deletes a full Menustrip
  1257.     and all connected data
  1258.  
  1259.     NOTES
  1260.  
  1261.     BUGS
  1262.  
  1263.     EXAMPLES
  1264.  
  1265.     SEE ALSO
  1266.     menucom/do_menuclear
  1267.  
  1268.     INTERNALS
  1269.  
  1270.     HISTORY
  1271.     19 Dec 1992 b_noll  created
  1272.  
  1273. ******************************************************************************/
  1274.  
  1275. void menuclear (MENUSTRIP * ms)
  1276. {
  1277.     struct Menu * menu;
  1278.  
  1279.     while ((menu = ms->data)) {
  1280.     menudel (ms, menu->MenuName);
  1281.     } /* while */
  1282.     ms->data = NULL;
  1283. } /* menuclear */
  1284.  
  1285.  
  1286.  
  1287. /*****************************************************************************
  1288.  
  1289.     NAME
  1290.     loadmenues
  1291.  
  1292.     PARAMETER
  1293.     MENUSTRIP * ms
  1294.     FILE      * fi
  1295.     int      * lineno
  1296.  
  1297.     RESULT
  1298.     success:
  1299.         RET_FAIL - error
  1300.         RET_SUCC - ok
  1301.  
  1302.     RETURN
  1303.     int
  1304.  
  1305.     DESCRIPTION
  1306.  
  1307.     NOTES
  1308.     we have used an implementation-decision here, that should
  1309.     better be invisible -
  1310.     macros must be accessible via their name, if that model is used
  1311.     else we have to rewrite parts of that function
  1312.  
  1313.     BUGS
  1314.     HELP may be redefined
  1315.  
  1316.     EXAMPLES
  1317.  
  1318.     SEE ALSO
  1319.     menucom/do_menuload
  1320.  
  1321.     INTERNALS
  1322.  
  1323.     HISTORY
  1324.     20 Jan 1993 b_null added check-handling
  1325.  
  1326. ******************************************************************************/
  1327.  
  1328. DEFMESSAGE( _MENU_read_unexpected_definition, "Unexpected %s Definition" )
  1329. #define UNEX_DEF   _MENU_read_unexpected_definition
  1330. #define EX_TITLE    1
  1331. #define EX_ITEM     2
  1332. #define EX_ITEMBAR  4
  1333. #define EX_SUB        8
  1334. #define EX_SUBBAR  16
  1335. #define EX_COM       32
  1336. #define EX_SCOM    64
  1337. #define EX_END      128
  1338. #define EX_SHORT  256
  1339. #define EX_HELP   512
  1340.  
  1341. /* #define EX_HELP   (EX_COM|EX_SCOM) / * buggy! */
  1342.  
  1343.  
  1344. /* PLANNED METHOD
  1345.  
  1346.      "START", 5, EX_START, PUSH, EX_END|EX_ITEM,
  1347.      "END",   3, EX_END,   POP,  EX_END|EX_ITEM,
  1348.      "BAR",   3, EX_ITEM,  SUB,  0,
  1349.      "ITEM",  4, EX_ITEM,  SET,                 EX_START|EX_HELP|EX_SCUT|EX_COM,
  1350.      "SHORT", 5, EX_SHORT, SUB,                 EX_START|        EX_SCUT,
  1351.      "HELP",  4, EX_HELP,  SUB,                 EX_START|EX_HELP,
  1352.      "COM",   3, EX_COM,   SET,  EX_END|EX_ITEM,
  1353. */
  1354.  
  1355. /* CURRENT METHOD
  1356.      "MENUSTRIP END",     , EX_END,   SET, 0,
  1357.      "TITLE ",           5, EX_TITLE, SET,                                EX_ITEM,
  1358.      "ITEM ",            4, EX_ITEM,  SET, EX_COM|EX_HELP|EX_SHORT|EX_SUB,
  1359.      "ITEMCHECK ",       9, EX_ITEM,  SET, EX_COM|EX_HELP|EX_SHORT,
  1360.      "ITEMBAR",          7, EX_ITEM,  SET,                                EX_ITEM|EX_TITLE,
  1361.      "HELP "              , EX_HELP,  SUB,        EX_HELP|         EX_SUB,
  1362.      "SHORT "             , EX_SHORT, SUB,                EX_SHORT|EX_SUB,
  1363.      "COM "               , EX_COM,   SET,                         EX_TTT|EX_ITEM|EX_TITLE,
  1364.      "SUB "               , EX_SUB,   SET, EX_COM|EX_HELP|EX_SHORT,
  1365.      "SUBCHECK "          , EX_SUB,   SET, EX_COM|EX_HELP|EX_SHORT,
  1366.      "SUBBAR"             , EX_SUB,   SET,                         EX_SUB|EX_ITEM|EX_TITLE,
  1367. */
  1368.  
  1369.  
  1370. int loadmenus (MENUSTRIP * ms, FILE * fi, int * lineno)
  1371. {
  1372.     char * buf;
  1373.     char   ntitle [128];
  1374.     char   nitem  [128];
  1375.     char   nsub   [128];
  1376.     char   body   [LINE_LENGTH];
  1377.     char   help   [LINE_LENGTH];
  1378.     char   scut   [32];
  1379.     char *pscut = NULL;
  1380. /*  int    doloop = -1; */
  1381.     int     check =  0;
  1382.     long expected;
  1383.  
  1384.     buf = getnextcomline (fi, lineno);
  1385.     if (!buf) {
  1386. DEFMESSAGE( _MENU_read_unexpected_eof, "Unexpected EndOfFile" )
  1387.     /* error (_MENU_read_unexpected_eof); */
  1388.     SET_ABORTION( 1 );
  1389.     return (RET_FAIL);
  1390.     } /* if */
  1391.     if (strncmp (buf, "MENUSTRIP START", 15) != 0) {
  1392. DEFMESSAGE( _MENU_read_no_header, "No Menustart header" )
  1393.     error    (_MENU_read_no_header);
  1394.     return    (RET_FAIL);
  1395.     } /* if */
  1396.  
  1397.     ntitle[0] = 0;
  1398.     nitem [0] = 0;
  1399.     nsub  [0] = 0;
  1400.     body  [0] = 0;
  1401.     help  [0] = 0;
  1402.     scut  [0] = 0;
  1403.  
  1404.     expected = EX_TITLE|EX_END;
  1405.  
  1406.     while (!IS_ABORTED()) {
  1407.     buf = getnextcomline (fi, lineno);
  1408.     if (!buf) {
  1409.         SET_ABORTION( 1 );
  1410.         return (RET_FAIL);
  1411.     } /* if */
  1412.  
  1413.     if (strncmp(buf, "MENUSTRIP END", 13) == 0) {
  1414.         if (!(expected & EX_END)) {
  1415. DEFMESSAGE( _MENU_read_unex_end_of_menu, "End Of Menu" )
  1416.         error  (UNEX_DEF, _MENU_read_unex_end_of_menu);
  1417.         return (RET_FAIL);
  1418.         } /* if */
  1419.         return (RET_SUCC);
  1420.  
  1421.     } else if (strncmp(buf, "TITLE ", 6) == 0) {
  1422.         if (!(expected & EX_TITLE)) {
  1423. DEFMESSAGE( _MENU_read_unex_menutitle, "MenuTitle" )
  1424.         error  (UNEX_DEF, _MENU_read_unex_menutitle);
  1425.         return (RET_FAIL);
  1426.         } /* if */
  1427.         expected = EX_ITEM|EX_ITEMBAR;
  1428.  
  1429.         buf += 6;
  1430.         strncpy (ntitle, buf, 128);
  1431.  
  1432.     } else if (strncmp(buf, "ITEM ", 5) == 0) {
  1433.         if (!(expected & EX_ITEM)) {
  1434. DEFMESSAGE( _MENU_read_unex_menuitem, "MenuItem" )
  1435.         error  (UNEX_DEF, _MENU_read_unex_menuitem);
  1436.         return (RET_FAIL);
  1437.         } /* if */
  1438.         expected = EX_SUB|EX_SUBBAR|EX_COM|EX_HELP|EX_SHORT;
  1439.  
  1440.         buf += 5;
  1441.         strncpy (nitem, buf, 128);
  1442.  
  1443.     } else if (strncmp(buf, "ITEMCHECK ", 10) == 0) {
  1444.         if (!(expected & EX_ITEM)) {
  1445. DEFMESSAGE( _MENU_read_unex_itemcheck, "ItemCheck" )
  1446.         error  (UNEX_DEF, _MENU_read_unex_itemcheck);
  1447.         return (RET_FAIL);
  1448.         } /* if */
  1449.         expected = EX_COM|EX_HELP|EX_SHORT;
  1450.  
  1451.         buf += 10;
  1452.         strncpy (nitem, buf, 128);
  1453.         check = 1;
  1454.  
  1455.     } else if (strncmp(buf, "ITEMBAR", 7) == 0) {
  1456.         if (!(expected & EX_ITEMBAR)) {
  1457. DEFMESSAGE( _MENU_read_unex_itembar, "MenuItembar" )
  1458.         error  (UNEX_DEF, _MENU_read_unex_itembar);
  1459.         return (RET_FAIL);
  1460.         } /* if */
  1461.         expected = EX_ITEM|EX_ITEMBAR|EX_TITLE|EX_END;
  1462.  
  1463.         itemadd (ms, ntitle, BAR, NULL, NULL, 0, NULL);
  1464.  
  1465.     } else if (strncmp(buf, "SUB ", 4) == 0) {
  1466.         if (!(expected & EX_SUB)) {
  1467. DEFMESSAGE( _MENU_read_unex_subitem, "SubItem" )
  1468.         error  (UNEX_DEF, _MENU_read_unex_subitem);
  1469.         return (RET_FAIL);
  1470.         } /* if */
  1471.         expected = EX_SCOM|EX_HELP|EX_SHORT;
  1472.  
  1473.         buf += 4;
  1474.         strncpy (nsub, buf, 128);
  1475.  
  1476.     } else if (strncmp(buf, "SUBCHECK ", 9) == 0) {
  1477.         if (!(expected & EX_SUB)) {
  1478. DEFMESSAGE( _MENU_read_unex_subitemcheck, "SubItemCheck" )
  1479.         error  (UNEX_DEF, _MENU_read_unex_subitemcheck);
  1480.         return (RET_FAIL);
  1481.         } /* if */
  1482.         expected = EX_SCOM|EX_HELP|EX_SHORT;
  1483.  
  1484.         buf += 9;
  1485.         strncpy (nsub, buf, 128);
  1486.         check = 1;
  1487.  
  1488.     } else if (strncmp(buf, "SUBBAR", 6) == 0) {
  1489.         if (!(expected & EX_SUBBAR)) {
  1490. DEFMESSAGE( _MENU_read_unex_subbar, "SubItembar" )
  1491.         error  (UNEX_DEF, _MENU_read_unex_subbar);
  1492.         return (RET_FAIL);
  1493.         } /* if */
  1494.         expected = EX_SUB|EX_SUBBAR|EX_TITLE|EX_ITEM|EX_ITEMBAR|EX_END;
  1495.  
  1496.         subadd (ms, ntitle, nitem, BAR, NULL, NULL, 0, NULL);
  1497.  
  1498. /* --- THAT BLOCK MUST BE CHANGED IF MACROS ARE MODIFIED */
  1499.     } else if (strncmp(buf, "HELP", 4) == 0 && (buf[4] < 33)) {
  1500.         if (!(expected & (EX_HELP))) {
  1501. DEFMESSAGE( _MENU_read_unex_helpfield, "Help" )
  1502.         error  (UNEX_DEF, _MENU_read_unex_helpfield);
  1503.         return (RET_FAIL);
  1504.         } /* if */
  1505.  
  1506.         buf += 3; if (*buf) buf++;
  1507.         strncpy (help, buf, LINE_LENGTH);
  1508.         expected &= ~EX_HELP;
  1509.  
  1510.     } else if (strncmp(buf, "SHORT", 5) == 0 && (buf[5] < 33)) {
  1511.         if (!(expected & (EX_SHORT))) {
  1512. DEFMESSAGE( _MENU_read_unex_shortcut, "Shortcut" )
  1513.         error  (UNEX_DEF, _MENU_read_unex_shortcut);
  1514.         return (RET_FAIL);
  1515.         } /* if */
  1516.  
  1517.         buf += 4; if (*buf) buf++;
  1518.         strncpy (scut, buf, sizeof (scut));
  1519.         expected &= ~EX_SHORT;
  1520.         pscut = scut;
  1521.  
  1522.     } else if (strncmp(buf, "COM", 3) == 0 && (buf[3] < 33)) {
  1523.         /* char * h2 = help[0] ? help : NULL; */
  1524.  
  1525.         if (!(expected & (EX_COM|EX_SCOM))) {
  1526. DEFMESSAGE( _MENU_read_unex_commandfield, "Command" )
  1527.         error  (UNEX_DEF, _MENU_read_unex_commandfield);
  1528.         return (RET_FAIL);
  1529.         } /* if */
  1530.         /* expected = 0; */
  1531.  
  1532.         buf += 3; if (*buf) buf++;
  1533.         strncpy (body, buf, LINE_LENGTH);
  1534.         if (expected & EX_SCOM) {
  1535.         expected = EX_SUB|EX_SUBBAR|EX_TITLE|EX_ITEM|EX_ITEMBAR|EX_END;
  1536.         subadd (ms, ntitle, nitem, nsub, body, help, check, pscut);
  1537.         } else {
  1538.         expected = EX_TITLE|EX_ITEM|EX_ITEMBAR|EX_END;
  1539.         itemadd (ms, ntitle, nitem,      body, help, check, pscut);
  1540.         } /* if */
  1541.         check   = 0;
  1542.         help[0] = 0;
  1543.         scut[0] = 0;
  1544.         pscut   = NULL;
  1545. /* --- THAT BLOCK MUST BE CHANGED IF MACROS ARE MODIFIED */
  1546.     } else {
  1547. DEFMESSAGE( _MENU_read_unknown_id, "%s:\nunknown identifier '%s'" )
  1548.         error (_MENU_read_unknown_id, CommandName(), buf);
  1549.     } /* if types */
  1550.     } /* while not ready */
  1551.     return(RET_FAIL);
  1552. } /* loadmenus */
  1553.  
  1554.  
  1555.  
  1556. /*****************************************************************************
  1557.  
  1558.     NAME
  1559.     chkitemcheck
  1560.  
  1561.     PARAMETER
  1562.     MENUSTRIP * ms
  1563.     char      * tname
  1564.     char      * iname
  1565.  
  1566.     RESULT
  1567.     -1 error
  1568.      0/1 status of check
  1569.  
  1570.     RETURN
  1571.     int
  1572.  
  1573.     DESCRIPTION
  1574.     check the status of a checkitem
  1575.  
  1576.     NOTES
  1577.     only works with items created as check-items
  1578.  
  1579.     BUGS
  1580.     none known
  1581.  
  1582.     EXAMPLES
  1583.  
  1584.     SEE ALSO
  1585.  
  1586.     INTERNALS
  1587.  
  1588.     HISTORY
  1589.     20 Jan 1993 b_null created
  1590.  
  1591. ******************************************************************************/
  1592.  
  1593. int chkitemcheck (MENUSTRIP * ms, char * tname, char * iname)
  1594. {
  1595.     struct MenuItem * item = (struct MenuItem *)getitem (ms, tname, iname);
  1596.     if ((!item) || !(item->Flags & (MENUTOGGLE|CHECKIT))) {
  1597.     return (-1);
  1598.     } /* if */
  1599.  
  1600.     if (item->Flags & CHECKED) {
  1601.     return (1);
  1602.     } /* if */
  1603.     return (0);
  1604. } /* chkitemcheck */
  1605.  
  1606.  
  1607.  
  1608. /*****************************************************************************
  1609.  
  1610.     NAME
  1611.     chksubcheck
  1612.  
  1613.     PARAMETER
  1614.     MENUSTRIP * ms
  1615.     char      * tname
  1616.     char      * iname
  1617.     char      * sname
  1618.  
  1619.     RESULT
  1620.     -1 error
  1621.      0/1 status of check
  1622.  
  1623.     RETURN
  1624.     int
  1625.  
  1626.     DESCRIPTION
  1627.     check the status of a check-subitem
  1628.  
  1629.     NOTES
  1630.     only works with subs created as check-subitems
  1631.  
  1632.     BUGS
  1633.     none known
  1634.  
  1635.     EXAMPLES
  1636.  
  1637.     SEE ALSO
  1638.  
  1639.     INTERNALS
  1640.  
  1641.     HISTORY
  1642.     20 Jan 1993 b_null created
  1643.  
  1644. ******************************************************************************/
  1645.  
  1646. int chksubcheck (MENUSTRIP * ms, char * tname, char * iname, char * sname)
  1647. {
  1648.     struct MenuItem * sub = (struct MenuItem *)getsub (ms, tname, iname, sname);
  1649.  
  1650.     if ((!sub) || !(sub->Flags & (MENUTOGGLE|CHECKIT))) {
  1651.     return (-1);
  1652.     } /* if */
  1653.  
  1654.     if (sub->Flags & CHECKED) {
  1655.     return (1);
  1656.     } /* if */
  1657.     return (0);
  1658. } /* chksubcheck */
  1659.  
  1660.  
  1661.  
  1662. /*****************************************************************************
  1663.  
  1664.     NAME
  1665.     setitemcheck
  1666.  
  1667.     PARAMETER
  1668.     MENUSTRIP * ms
  1669.     char      * tname
  1670.     char      * iname
  1671.  
  1672.     RESULT
  1673.     success :
  1674.         RET_FAIL - not found or error
  1675.         RET_SUCC - ok
  1676.  
  1677.     RETURN
  1678.     int
  1679.  
  1680.     DESCRIPTION
  1681.     set the status of a check-item
  1682.  
  1683.     NOTES
  1684.     only works with items created as check-items
  1685.  
  1686.     BUGS
  1687.     none known
  1688.  
  1689.     EXAMPLES
  1690.  
  1691.     SEE ALSO
  1692.  
  1693.     INTERNALS
  1694.  
  1695.     HISTORY
  1696.     20 Jan 1993 b_null created
  1697.  
  1698. ******************************************************************************/
  1699.  
  1700. int setitemcheck (MENUSTRIP * ms, char * tname, char * iname, int status)
  1701. {
  1702.     struct MenuItem * item = (struct MenuItem *)getitem (ms, tname, iname);
  1703.  
  1704.     if ((!item) || !(item->Flags & (MENUTOGGLE|CHECKIT))) {
  1705.     return (RET_FAIL);
  1706.     } /* if */
  1707.  
  1708.     if (status) {
  1709.     item->Flags |= CHECKED;
  1710.     } else {
  1711.     item->Flags &= ~CHECKED;
  1712.     } /* if */
  1713.     return (RET_SUCC);
  1714. } /* setitemcheck */
  1715.  
  1716.  
  1717.  
  1718. /*****************************************************************************
  1719.  
  1720.     NAME
  1721.     setsubcheck
  1722.  
  1723.     PARAMETER
  1724.     MENUSTRIP * ms
  1725.     char      * tname
  1726.     char      * iname
  1727.     char      * sname
  1728.  
  1729.     RESULT
  1730.     success :
  1731.         RET_FAIL - not found or error
  1732.         RET_SUCC - ok
  1733.  
  1734.     RETURN
  1735.     int
  1736.  
  1737.     DESCRIPTION
  1738.     set the status of a check-subitem
  1739.  
  1740.     NOTES
  1741.     only works with subs created as check-subitems
  1742.  
  1743.     BUGS
  1744.     none known
  1745.  
  1746.     EXAMPLES
  1747.  
  1748.     SEE ALSO
  1749.  
  1750.     INTERNALS
  1751.  
  1752.     HISTORY
  1753.     20 Jan 1993 b_null created
  1754.  
  1755. ******************************************************************************/
  1756.  
  1757. int setsubcheck (MENUSTRIP * ms, char * tname, char * iname, char * sname, int status)
  1758. {
  1759.     struct MenuItem * sub = (struct MenuItem *)getsub (ms, tname, iname, sname);
  1760.  
  1761.     if ((!sub) || !(sub->Flags & (MENUTOGGLE|CHECKIT))) {
  1762.     return (RET_FAIL);
  1763.     } /* if */
  1764.  
  1765.     if (status) {
  1766.     sub->Flags |= CHECKED;
  1767.     } else {
  1768.     sub->Flags &= ~CHECKED;
  1769.     } /* if */
  1770.     return (RET_SUCC);
  1771. } /* setsubcheck */
  1772.  
  1773.  
  1774.  
  1775.  
  1776.  
  1777.  
  1778.  
  1779.  
  1780. /* old DATA */
  1781.  
  1782. /*
  1783. **  Die Folgenden functionen haben noch keine Header
  1784. **  und sind teilweise noch nicht fertig
  1785. */
  1786.  
  1787.  
  1788. /*****************************************************************************
  1789.  
  1790.     NAME
  1791.     def_menus
  1792.  
  1793.     PARAMETER
  1794.     MENUSTRIP * ms
  1795.  
  1796.     RESULT
  1797.  
  1798.     RETURN
  1799.  
  1800.     DESCRIPTION
  1801.  
  1802.     NOTES
  1803.  
  1804.     BUGS
  1805.  
  1806.     EXAMPLES
  1807.  
  1808.     SEE ALSO
  1809.  
  1810.     INTERNALS
  1811.  
  1812.     HISTORY
  1813.     Jan 1993 b_null created
  1814.  
  1815. ******************************************************************************/
  1816.  
  1817.  
  1818. int def_menus (MENUSTRIP * ms)
  1819. {
  1820.  
  1821.     ms->offCount = 1;
  1822.     menuclear (ms);
  1823.  
  1824. #   ifdef NOT_DEF /* PATCH_NULL [04 Feb 1993] : Hierher koennte noch ein Default-menue eintrag */
  1825.     {
  1826.     int i;
  1827.     int succ;
  1828.     for (i = 0, succ = RET_SUCC; (succ == RET_SUCC) && (def_menu[i].title != NULL); i++) {
  1829.         if (def_menu[i].sub) {
  1830.         succ = subadd  (ms, def_menu[i].title, def_menu[i].item, def_menu[i].sub, def_menu[i].body, def_menu[i].help, def_menu[i].check, NULL);
  1831.         } else {
  1832.         succ = itemadd (ms, def_menu[i].title, def_menu[i].item,                  def_menu[i].body, def_menu[i].help, def_menu[i].check, NULL);
  1833.         } /* if sub */
  1834.     } /* for def_menu */
  1835.     }
  1836. #   endif
  1837.     ms->offCount = 0;
  1838.  
  1839.     return (RET_SUCC);
  1840. } /* def_menus */
  1841.  
  1842.  
  1843.  
  1844.  
  1845. /*****************************************************************************
  1846.  
  1847.     NAME
  1848.     split_menu_names
  1849.  
  1850.     PARAMETER
  1851.     char *    source
  1852.     char ** menu
  1853.     char ** item
  1854.     char ** sub
  1855.  
  1856.     RESULT
  1857.     success:
  1858.         RET_SUCC == everythink ok
  1859.         RET_FAIL == any failure
  1860.  
  1861.     RETURN
  1862.     int
  1863.  
  1864.     DESCRIPTION
  1865.     that function is to extract the menu-, item- and subitem-
  1866.     names out of a single string
  1867.  
  1868.     there is no test, if these extracted names are part of a menustrip
  1869.  
  1870.     NOTES
  1871.     the MENU_DELIMITER must not be part of a menuname
  1872.     the ITEM_DELIMITER must not be part of an itemname
  1873.     else we might get serious problems
  1874.  
  1875.     BUGS
  1876.  
  1877.     EXAMPLES
  1878.  
  1879.     SEE ALSO
  1880.  
  1881.     INTERNALS
  1882.     suche nach dem MENU_DELIMITER,
  1883.         kopiere den string bis dort nach menuname
  1884.     suche nach dem ITEM_DELIMITER
  1885.         gefunden -> kopiere den string bis dort nach itemname,
  1886.             den rest nach subname
  1887.         sonst    -> kopiere den string nach itemname
  1888.  
  1889.     HISTORY
  1890.     01 Feb 1993 b_null created
  1891.  
  1892. ******************************************************************************/
  1893.  
  1894. int split_menu_names (char * source, char ** menu, char ** item, char ** sub)
  1895. {
  1896.     static char menuname[128];
  1897.     static char itemname[128];
  1898.     static char subname [128];
  1899.     int     i;
  1900.  
  1901.     *menu = NULL;
  1902.     *item = NULL;
  1903.     *sub  = NULL;
  1904.  
  1905.     for (i = 0; source[i] && source[i] != MENU_DELIMITER; ++i);
  1906.     if (source[i] == MENU_DELIMITER) {
  1907.     /* Punkt 1 : hier bin ich noch nicht zufrieden: was passiert, wenn ein name ein '-' enthaelt */
  1908.     strncpy(menuname, source, i);
  1909.     menuname[i] = 0;
  1910.     *menu = menuname;
  1911.  
  1912.     source += (i+1);
  1913.     for (i = 0; source[i] && source[i] != ITEM_DELIMITER; ++i);
  1914.     strncpy(itemname, source, i);
  1915.     *item = itemname;
  1916.     itemname[i] = 0;
  1917.  
  1918.     if (source[i] == ITEM_DELIMITER) {
  1919.         source += (i+1);
  1920.         strcpy (subname, source);
  1921.         *sub  = subname;
  1922.     } /* if contains subname */
  1923.     return (RET_SUCC);
  1924.     } /* if contains itemname */
  1925.     return (RET_FAIL);
  1926. } /* split_menu_names */
  1927.  
  1928.  
  1929.  
  1930. /*****************************************************************************
  1931.  
  1932.     NAME
  1933.     findmenu
  1934.  
  1935.     PARAMETER
  1936.     MENUSTRIP * ms
  1937.     char      * name
  1938.  
  1939.     RESULT
  1940.  
  1941.     RETURN
  1942.  
  1943.     DESCRIPTION
  1944.  
  1945.     NOTES
  1946.  
  1947.     BUGS
  1948.  
  1949.     EXAMPLES
  1950.  
  1951.     SEE ALSO
  1952.  
  1953.     INTERNALS
  1954.  
  1955.     HISTORY
  1956.     29 Dec 1992 b_null created
  1957.     01 Feb 1993 b_null splitted
  1958.  
  1959. ******************************************************************************/
  1960.  
  1961. struct MenuItem * findmenu (MENUSTRIP * ms, char * str)
  1962. {
  1963.     char        * header;
  1964.     char        * itembuf;
  1965.     char        * subbuf;
  1966.     struct Menu     * menu;
  1967.     struct MenuItem * item;
  1968.     struct MenuItem * sub;
  1969.  
  1970.     split_menu_names (str, &header, &itembuf, &subbuf);
  1971.  
  1972.     if ((header) && (menu = getmenu (ms, header))) {
  1973.     if ((itembuf) && (item   = (struct MenuItem *)get_xitem ((XITEM *)menu->FirstItem, itembuf))) {
  1974.         if ((subbuf) && (sub = (struct MenuItem *)get_xitem ((XITEM *)item->SubItem, subbuf))) {
  1975.         return (sub);
  1976.         } else if (subbuf) {
  1977.         return (NULL);
  1978.         } /* if subitem */
  1979.         return (item);
  1980.     } /* if found item */
  1981.     } /* if found menu */
  1982.     return (NULL);
  1983. } /* findmenu */
  1984.  
  1985.  
  1986. /*****************************************************************************
  1987.  
  1988.     NAME
  1989.     menu2macro
  1990.  
  1991.     PARAMETER
  1992.     MENUSTRIP * ms
  1993.     char      * name
  1994.  
  1995.     RESULT
  1996.     the macro used by the menu name
  1997.  
  1998.     RETURN
  1999.     APTR
  2000.  
  2001.     DESCRIPTION
  2002.  
  2003.     NOTES
  2004.     perhaps user has to call macroname, macrohelp or sthng like that
  2005.     to get the wanted information
  2006.  
  2007.     BUGS
  2008.  
  2009.     EXAMPLES
  2010.  
  2011.     SEE ALSO
  2012.  
  2013.     INTERNALS
  2014.  
  2015.     HISTORY
  2016.     20 Dec 1992 b_null created
  2017.  
  2018. ******************************************************************************/
  2019.  
  2020. APTR menu2macro (MENUSTRIP * ms, char * str)
  2021. {
  2022.     XITEM * xi;
  2023.  
  2024.     if ((xi = (XITEM *)findmenu (ms, str))) {
  2025.     if (xi->com) {
  2026.         return (xi->com);
  2027.     } /* if */
  2028.     } /* if */
  2029.     return (NULL);
  2030. } /* menu2macro */
  2031.  
  2032.  
  2033.  
  2034.  
  2035.  
  2036. /*****************************************************************************
  2037.  
  2038.     BASIC FUNCTIONS ON MENUSTRIPS :
  2039.  
  2040.     get, new, delete
  2041.  
  2042.     all menustrips created with new_menustrip are deleted at program termination
  2043.  
  2044. *****************************************************************************/
  2045.  
  2046. /*****************************************************************************
  2047.  
  2048.     NAME
  2049.     get_menustrip
  2050.  
  2051.     PARAMETER
  2052.     char * name
  2053.  
  2054.     RESULT
  2055.     the menustrip with the name name, if it is already existing
  2056.     else NULL
  2057.  
  2058.     RETURN
  2059.     MENUSTRIP *
  2060.  
  2061.     DESCRIPTION
  2062.     search function on the hidden list of menustrips
  2063.  
  2064.     NOTES
  2065.     useful only, if we are using multiple menustrips
  2066.  
  2067.     BUGS
  2068.  
  2069.     EXAMPLES
  2070.  
  2071.     SEE ALSO
  2072.  
  2073.     INTERNALS
  2074.  
  2075.     HISTORY
  2076.     27 Jan 1993 b_null created
  2077.  
  2078. ******************************************************************************/
  2079.  
  2080. MENUSTRIP * get_menustrip (char * name)
  2081. {
  2082.     if (!MenuStrips)
  2083.     return NULL;
  2084.  
  2085.     if (name == NULL)
  2086.     return (GetHead (MenuStrips));
  2087.  
  2088.     return (MENUSTRIP *)FindName (MenuStrips, name);
  2089. } /* get_menustrip */
  2090.  
  2091.  
  2092.  
  2093. /*****************************************************************************
  2094.  
  2095.     NAME
  2096.     delete_menustrip
  2097.  
  2098.     PARAMETER
  2099.     MENUSTRIP * ms
  2100.     int        force
  2101.  
  2102.     RESULT
  2103.     -/-
  2104.  
  2105.     RETURN
  2106.     void
  2107.  
  2108.     DESCRIPTION
  2109.     delete a full menustrip
  2110.     that function does NOT delete the last menustrip,
  2111.     unless force is set to 1
  2112.  
  2113.     NOTES
  2114.     useful only, if we are using multiple menustrips
  2115.  
  2116.     that function does NOT take care of any references to a menustrip
  2117.     You must do that job on a higher abstraction-level
  2118.         (e.g. in menucom.c - for all ED's if )
  2119.  
  2120.     BUGS
  2121.  
  2122.     EXAMPLES
  2123.  
  2124.     SEE ALSO
  2125.  
  2126.     INTERNALS
  2127.     ausklinken aus der menustrip-liste
  2128.     loeschen der menuestruktur
  2129.     loeschen des namens
  2130.     loeschen des bodies
  2131.  
  2132.     HISTORY
  2133.     27 Jan 1993 b_null created
  2134.  
  2135. ******************************************************************************/
  2136.  
  2137. void delete_menustrip (MENUSTRIP * ms, int force)
  2138. {
  2139.     if (ms) {
  2140.     if ((!force) && (GetSucc(ms) == NULL) && (GetPred(ms) == NULL)) {
  2141.         return;
  2142.     } /* if */
  2143.  
  2144.     menuclear (ms);
  2145.  
  2146. #if 0
  2147.     Remove (&ms->node);
  2148.     DeallocFunc (ms->node.ln_Name);
  2149. #else
  2150.     HL_Uninit(&ms->node);
  2151. #endif
  2152.     FreeFunc    (ms, sizeof (MENUSTRIP));
  2153.     } /* if */
  2154. } /* delete_menustrip */
  2155.  
  2156.  
  2157.  
  2158. /*****************************************************************************
  2159.  
  2160.     NAME
  2161.     new_menustrip
  2162.  
  2163.     PARAMETER
  2164.     char * name
  2165.     int    defaults
  2166.  
  2167.     RESULT
  2168.     either a new menustrip, if there is not already one with that name
  2169.     or the first menustrip, that matches that name
  2170.     if we have to create a new one, we can set defaults to 1 to
  2171.     fill in the default-menustrip
  2172.  
  2173.     RETURN
  2174.     MENUSTRIP *
  2175.  
  2176.     DESCRIPTION
  2177.  
  2178.     NOTES
  2179.     useful only, if we are using multiple menustrips
  2180.  
  2181.     if we can fill in only parts of the deafult-information,
  2182.     we do NOT fail
  2183.  
  2184.     BUGS
  2185.  
  2186.     EXAMPLES
  2187.  
  2188.     SEE ALSO
  2189.  
  2190.     INTERNALS
  2191.  
  2192.     HISTORY
  2193.     27 Jan 1993 b_noll created
  2194.  
  2195. ******************************************************************************/
  2196.  
  2197. MENUSTRIP * new_menustrip (char * name, int defaults)
  2198. {
  2199.     MENUSTRIP * ms;
  2200.  
  2201.     if (!MenuStrips)
  2202.     return NULL;
  2203.  
  2204.     if ((ms = get_menustrip(name))) {
  2205.     /* goto newvalue; */ /* that way we do reset an existing menustrip, if we call new */
  2206.     return (ms);         /* that way we only use an existing menustrip, if we call new */
  2207.     } /* if */
  2208.  
  2209.     ms = AllocFunc (sizeof(MENUSTRIP), MEMF_ANY);
  2210.     if (ms == NULL) {
  2211.     return (NULL);
  2212.     } /* if */
  2213.  
  2214.     bzero (ms, sizeof(MENUSTRIP));
  2215. #if 0
  2216.     ms->node.ln_Name = DupFunc (name, MEMF_ANY);
  2217.     if (ms->node.ln_Name == NULL) {
  2218.     FreeFunc (ms, sizeof (MENUSTRIP));
  2219.     return (NULL);
  2220.     } /* if */
  2221.  
  2222.     AddTail (MenuStrips, &ms->node);
  2223. #else
  2224.     if (HL_Init(&ms->node, name, MenuRoot, HLF_SYSNODE) != HL_OK) {
  2225.     FreeFunc (ms, sizeof (MENUSTRIP));
  2226.     return (NULL);
  2227.     } /* if */
  2228. #endif
  2229.  
  2230. /* newvalue: */
  2231.  
  2232.     if (defaults) {
  2233.     def_menus (ms);
  2234.     } /* if */
  2235.  
  2236.     return (ms);
  2237. } /* new_menustrip */
  2238.  
  2239.  
  2240.  
  2241. /*****************************************************************************
  2242.  
  2243.     NAME
  2244.     init_menustrips
  2245.     exit_menustrips
  2246.  
  2247.     PARAMETER
  2248.     void
  2249.  
  2250.     RESULT
  2251.     -/-
  2252.  
  2253.     RETURN
  2254.     void
  2255.  
  2256.     DESCRIPTION
  2257.     init and exit functions for menustrips
  2258.  
  2259.     NOTES
  2260.     useful only, if we are using multiple menustrips
  2261.  
  2262.     THESE are __AUTOEXIT/__AUTOEXIT - functions !!!!
  2263.  
  2264.     HISTORY
  2265.     27 Jan 1993 b_null created
  2266.  
  2267. ******************************************************************************/
  2268.  
  2269.  
  2270. DEFAUTOINIT( init_menustrips )
  2271. {
  2272. //puts (__FILE__);
  2273. #if 0
  2274.     MenuStrips = &_MenuStrips;
  2275.     NewList    (MenuStrips);
  2276. #else
  2277.     MenuRoot   = HL_SystemList("*Menustrips*");
  2278.     MenuStrips = HL_LockSubs(MenuRoot);
  2279.     HL_UnlockSubs(MenuRoot);
  2280. #endif
  2281.     menufont_ta.ta_Name = strdup ("*Screenfont*");
  2282.     new_menustrip ("default",1);
  2283. } /* init_menustrips */
  2284.  
  2285.  
  2286. DEFAUTOEXIT( exit_menustrips )
  2287. {
  2288.     MENUSTRIP * ms;
  2289.  
  2290.     if (MenuStrips)
  2291.     while ((ms = GetHead (MenuStrips)))
  2292.         delete_menustrip (ms, 1);
  2293. #if 1
  2294.     HL_Dispose(MenuRoot);
  2295. #endif
  2296. } /* exit_menustrips */
  2297.  
  2298.  
  2299.  
  2300.  
  2301. /******************************************************************************
  2302. *****  ENDE menustrips.c
  2303. ******************************************************************************/
  2304.